<?php
function list_sk(){

//PASANG JAVASCRIPT
	my_set_code_js('
	function confirmDelete(id){
		var t = confirm(\'Yakin akan menghapus data ?\');
		if(t){
			location.href=\'index.php?com=jabatan&task=deletesk&id=\'+id;
		}
		return false;
	}
	');
	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'), 
		'SK No.'=>array('style'=>'border-bottom:2px solid;width:35%'),  
		'Tanggal Efektif'=>array('style'=>'text-align:left;border-bottom:2px solid;width:30%'),   
		'Aktif'=>array('style'=>'border-bottom:2px solid;width:10%'), 
		' '=>array('style'=>'border-bottom:2px solid;width:20%'), 
	);

	$query = "SELECT * FROM sk_jabatan" ;
	
	$result = my_query($query);
	$i = 0;
	$row=array();
	while($ey = my_fetch_array($result)){
		$i++;
		$detailproperty = array(
			'href'=>'index.php?com=jabatan&task=list_jabatan&sk_id='.$ey['sk_id'], 
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		$editproperty = array(
			'href'=>'index.php?com=jabatan&task=edit_sk&id='.$ey['sk_id'],
			'rel'=>'facebox',
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$query="SELECT jabatan_id FROM jabatan 
			WHERE sk_id=".$ey['sk_id']; 
		if (my_num_rows( my_query($query)) >0){
			$delete_button = button_icon( 'b_drop_off.png' , ''  );
		}else{		
			$deleteproperty = array(
				'href'=>'javascript:; ',
				'onclick'=>'javascript:confirmDelete('.$ey['sk_id'].');',
				'title'=>'Delete'
			);
			$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		}
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'nomor'=>  $ey['nomor_sk'] ,
			'tanggal'	=> position_text_align ( date("d-m-Y", strtotime($ey['tanggal'] ." 00:00:00" ) ), 'left'), 
			'aktif'=> $ey['active'],
			'operasi'=> position_text_align(  $detail_button.' '.$edit_button.' '.$delete_button , 'right'),  
		);
		 
	}
	$datas = table_rows($row);  
	return   table_builder($header , $datas ,  5 , false  );
}

function form_sk( $id ){
	my_set_file_js(
		array(
			'components/system/jquery/combomulti/jquery.chainedSelects.js',
			'components/system/js/calendar/calendarDateInput.js' 
		)
	);

	$view = form_header( "seleski" , "seleski"  );
	$ftanggal= date('d-m-Y');
	$fields = my_get_data_by_id('sk_jabatan','sk_id',$id);
	if($fields){
		list($yyyytanggal , $mmtanggal,$ddtanggal ) = explode("-" ,$fields['tanggal'] );
		$ftanggal = $ddtanggal.'-'.$mmtanggal.'-'.$yyyytanggal;
	} 

	$nomor_sk = array(
			'name'=>'nomor_sk',
			'value'=>(isset($_POST['nomor_sk'])? $_POST['nomor_sk'] : $fields['nomor_sk']),
			'id'=>'nomor_sk',
			'type'=>'textfield',
			'size'=>'35'
		);
	$form_nomor = form_dynamic($nomor_sk);
	$view .= form_field_display( $form_nomor  , "Nomor SK"  );

	$tanggal = array(
			'name'=>'tanggal',
			'value'=>(isset($_POST['tanggal'])? $_POST['tanggal'] : $ftanggal),
			'id'=>'tanggal',
			'type'=>'textfield',
			'size'=>'45'
		);
	$form_tanggal = form_calendar($tanggal);
	$view .= form_field_display( $form_tanggal  , "Tanggal Efektif" );

	if($fields['active']=='Y'){ 
		$active = array(
			'name'=>'active',
			'id'=>'active',
			'type'=>'checkbox',
			'checked'=>'checked'
		);
	}else{
		$active = array(
			'name'=>'active',
			'id'=>'active',
			'type'=>'checkbox',
		); 
	}
	$form_active = form_dynamic($active).'Aktif';
	$view .= form_field_display( $form_active , "" );
	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}

function submit_sk($id = 0){
	if($_POST){
		list( $ddtanggal, $mmtanggal,$yyyytanggal ) = explode("-" ,$_POST['tanggal'] );
		$ftanggal = $yyyytanggal.'-'.$mmtanggal.'-'.$ddtanggal;
		 
	}
	$active = isset($_POST['active']) ? 'Y': 'T';	
	
	if($active=='Y'){
		$query= "UPDATE sk_jabatan SET active = 'T' " ;
		$temp=my_query($query);
	}
	$datas = array(
		'nomor_sk'=>my_type_data_str($_POST['nomor_sk']),
		'tanggal'=> my_type_data_str($ftanggal),	
		'active'=>my_type_data_str($active), 
	);
	 
	if($id > 0){
	
		return my_update_record('sk_jabatan','sk_id',$id,$datas);
	}
	$new_id = my_insert_record('sk_jabatan',$datas);
	return $new_id;
}

function form_sk_validate($sk_id){
	$errsubmit = false;
	$err = array();
	 
	$code =  trim($_POST["nomor_sk"]); 
	if( $code == ''){
		$errsubmit = true;
		$err[] = "Nomor SK belum di isi";
	}

	$query="SELECT sk_id FROM sk_jabatan 
		WHERE nomor_sk='".$code.
		"' AND sk_id<>".$sk_id; 
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Nomor SK sudah digunakan";	
	}
	
	$active = isset($_POST['active']) ? 'Y': 'T';	
	if( $active=='T' ){
		$query="SELECT sk_id FROM sk_jabatan 
			WHERE active='Y' AND sk_id<>".$sk_id; 
		if (my_num_rows( my_query($query)) ==0){
			$errsubmit = true;
			$err[] = "SK harus ada yang berstatus aktif";	
		}
	}	
 
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}

function delete_sk($id){
	$query= "DELETE FROM sk_jabatan WHERE sk_id = {$id}";
	return my_query($query);
} 


//=============================== END OF SK ==========================
	
function list_jabatan($sk_id,$parent_id){
	if(isset($_GET['key']) and $_GET['key']<>"" ){
		$query = "SELECT parent_id FROM jabatan  
			WHERE nomor_posisi ='{$_GET['key']}' 
			AND sk_id={$sk_id}";
		$atemp = my_fetch_array(my_query($query));
		if( $atemp ){
			$parent_id=$atemp['parent_id'] ;
			my_direct('index.php?com='.$_GET['com'].'&task=list_jabatan&sk_id='.$sk_id.'&parent_id='.$parent_id);
		}
	}

	//PASANG JAVASCRIPT
	my_set_code_js('
		function confirmDelete(id){
			var t = confirm(\'Yakin akan menghapus data ?\');
			if(t){
				location.href=\'index.php?com='.$_GET['com'].'&task=delete_jabatan&id=\'+id;
			}
			return false;
		}
	');
	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Nama Jabatan'=>array('style'=>'border-bottom:2px solid;width:35%'), 
		'Nama Organisasi'=>array('style'=>'border-bottom:2px solid;width:30%'), 
		'No. Posisi'=>array('style'=>'border-bottom:2px solid;width:15%'), 
		'Level'=>array('style'=>'border-bottom:2px solid;width:5%'), 
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);

	$query = "SELECT * FROM jabatan  
		WHERE parent_id ={$parent_id} 
		AND sk_id={$sk_id} 
		ORDER BY level , nomor_posisi";
		
	$result = my_query($query);
	$i = 0;
	$row=array();
	while($ey = my_fetch_array($result)){
		$i++;
		$moreproperty = array(
			'href'=>'index.php?com='.$_GET['com'].
			'&task=list_jabatan&sk_id='.$sk_id.
			'&parent_id='.$ey['jabatan_id'], 
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $moreproperty  );
		$editproperty = array(
			'href'=>'index.php?com='.$_GET['com'].'&task=editdevisi
				&sk_id='.$sk_id.'
				&parent_id='.$parent_id.'
				&id='.$ey['jabatan_id'],
			'rel'=>'facebox',
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );
		
		if(is_not_parent($ey['jabatan_id']) AND is_max($ey['jabatan_id'], $parent_id)){
			$deleteproperty = array(
				'href'=>'javascript:; ',
				'onclick'=>'javascript:confirmDelete('.$ey['jabatan_id'].');',
				'title'=>'Delete'
			);
			$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		}else{
			$deleteproperty = array(
				'href'=>'javascript:; ',
				'onclick'=>'javascript:alert(\'Data digunakan oleh proses lainnya\');',
				'title'=>'Delete'
			);
			$delete_button = button_icon( 'b_drop_off.png' , $deleteproperty  );
		} 
		$nama_jabatan=  $ey['nama_jabatan'];
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'divisi'=> $nama_jabatan ,   
			'organisasi'=>  $ey['nama_organisasi'] ,   
			'kode'=>   $ey['nomor_posisi'],   
			'grade'=>  $ey['level'],   
			'operasi'=> position_text_align(  $detail_button.' '.$edit_button.' '.$delete_button , 'right'),  
		);
	}
	$datas = table_rows($row);	
	$path = '';
	$temp = $parent_id;
	while($temp > 0 ){
		$jab = my_get_data_by_id('jabatan','jabatan_id', $temp);
		$path =' &gt; '.ucfirst(strtolower($jab['nama_jabatan'])).$path ;
		$temp = (int) $jab['parent_id'];
	}	
	$key = isset($_GET['key']) ? trim($_GET['key']): '';
	$search ='<form method="GET">
	<input type="hidden" name="com" value="'.$_GET["com"].'" />
	<input type="hidden" name="task" value="'.$_GET["task"].'" />
	<input type="hidden" name="sk_id" value="'.$sk_id.'" />
	<input type="hidden" name="parent_id" value="'.$parent_id.'" />
	<table border="0" width="100%"> <tr>
	<td width="20%">Nomor Posisi</td>
	<td width="10%"><input type="text"  style="width:80px;" name="key" value="'.$key.'" />
	<td width="10%"> <input type="submit" value="Cari"/></td>
	<td align="right">  	
	</td></tr></table></form>';
	
	$sk = my_get_data_by_id('sk_jabatan','sk_id',$sk_id);
	$view ='<table width="98%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "detail pegawai" , "cp"  );
	$view .= form_field_display( '<span class="label_form">'.  $sk['nomor_sk'] .'</span>'   , "<b>Nomor SK</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.   date( "d-m-Y" , strtotime($sk['tanggal'].' 00:00:00')).'</span>'   , "<b>Tanggal</b>"    ); 	
	$view .= form_footer( );
	$track ='</div>'.$path.'</div>';
	return $track .'<br/>' .$view.'<br/>' /*. $search*/.table_builder($header , $datas ,  6	 , false );
}

function is_not_parent($jabatan_id){
	$query = "SELECT jabatan_id FROM jabatan WHERE parent_id={$jabatan_id}";
	$result = my_query($query);
	if( my_num_rows($result) > 0 ){
		return false;
	}
	return true;
}

function is_max($jabatan_id , $parent_id){
	$query = "SELECT MAX(jabatan_id) AS maxima FROM jabatan WHERE parent_id={$parent_id} ";
	$result = my_query($query);
	$row = my_fetch_array($result);
	$mymax= $row['maxima'];
	
	if($mymax  == $jabatan_id ){
		return true;
	} 
	return false;
}

function form_jabatan_create($sk_id, $parent_id , $id = 0){
	$fields = my_get_data_by_id('jabatan','jabatan_id',$id);
	$gid=$fields['golongan_jabatan_id'];
	my_set_code_js('
		function checkNipar( ){
			var vfield = $(\'#sumber_pendukung\').val();
			$.get("hitung_nipar.php", { gid: '.$gid.' , field: vfield },
			   function(data){ 
					$(\'#nipar_data\').replaceWith(\'<span id="nipar_data">\'+data+\'</span>\'); 
			   }
			);
		}
	');

	$view = form_header( "devisi" , "devisi"  );
	
	
	$query = "SELECT * FROM departemen ORDER BY nama_departemen ASC";
	$result = my_query($query);
	$atemps = array();
	while( $r = my_fetch_array($result) ){
		$atemps[$r['departemen_id']] =$r['nama_departemen'];
	}	
	$temp = array(
		'name'=>'departemen_id',
		'value'=>( isset($_POST['departemen_id'] ) ? $_POST['departemen_id'] : $fields['departemen_id']  ),
		'id'=>'departemen_id' 
	);
	$form_temp = form_dropdown($temp , $atemps );
	$view .= form_field_display( $form_temp , "Departemen"    );
	
	$query = "SELECT * FROM pos_biaya ORDER BY pos_biaya_id ASC";
	$result = my_query($query);
	$temps = array();
	while( $r = my_fetch_array($result) ){
		$temps[$r['pos_biaya_id']] =$r['code']."-".$r['label'];
	}	
	$temp = array(
		'name'=>'pos_biaya_id',
		'value'=>( isset($_POST['pos_biaya_id'] ) ? $_POST['pos_biaya_id'] : $fields['pos_biaya_id']  ),
		'id'=>'pos_biaya_id'  
	);
	$form_temp = form_dropdown($temp , $temps );
	$view .= form_field_display( $form_temp , "Pos Biaya"    );
 
	$queryu = "SELECT * FROM unit ORDER BY unit_id ASC";
	$resultu = my_query($queryu);
	$tempsu = array();
	while( $ru = my_fetch_array($resultu) ){
		$tempsu[$ru['unit_id']] =$ru['nama_unit'] ;
	}	
	$tempu = array(
		'name'=>'form_jabatan_create',
		'value'=>( isset($_POST['form_jabatan_create'] ) ? $_POST['form_jabatan_create'] : $fields['form_jabatan_create']  ),
		'id'=>'form_jabatan_create'  
	);
	$form_tempu = form_dropdown($tempu , $tempsu );
	$view .= form_field_display( $form_tempu , "Unit/ Cabang"    );
 
  	$parent = my_get_data_by_id('jabatan','jabatan_id',$parent_id);
	if($parent_id > 0){ 
		$view .= form_field_display( $parent['nama_jabatan']   , "Jabatan Atasan"   );
	}
	
	
	$nomor_posisi = array(
		'name'=>'nomor_posisi',
		'value'=>( isset($_POST['nomor_posisi']) ? $_POST['nomor_posisi'] : $fields['nomor_posisi'] ),
		'id'=>'nomor_posisi',
		'type'=>'text',
		'size'=>'45'
	);
	$form_field_nomor_posisi = form_dynamic($nomor_posisi); 
	$view .= form_field_display( $form_field_nomor_posisi   , "Nomor posisi"   );
	
	$nama = array(
		'name'=>'nama_jabatan',
		'value'=>( isset($_POST['nama_jabatan']) ? $_POST['nama_jabatan'] : $fields['nama_jabatan'] ),
		'id'=>'nama_jabatan',
		'type'=>'text',
		'size'=>'45'
	);
	$form_field_nama = form_dynamic($nama); 
	$view .= form_field_display( $form_field_nama   , "Nama Jabatan"   );
	
	if($id>0){
		$view .= form_field_display(  $fields['level']   , "Level"   );	
	}else{
		$levels = array();
		for($i=$parent['level']+1; $i<=8; $i++){
			$levels[$i] =$i;
		}
		$level = array(
			'name'=>'level',
			'value'=>( isset($_POST['level']) ? $_POST['level'] : $fields['level'] ),
			'id'=>'level', 
		);
		$form_temp = form_dropdown($level , $levels );
		$view .= form_field_display( $form_temp , "Level"    );
	}	
	$goljab_id = isset( $fields['golongan_jabatan_id'] ) ? $fields['golongan_jabatan_id']:  0;
	$query = "SELECT * FROM golongan_jabatan ORDER BY kode_golongan_jabatan ASC";
	$result = my_query($query);
	$goljabs = array();
	while( $r = my_fetch_array($result) ){
		$goljabs[$r['golongan_jabatan_id']] =$r['kode_golongan_jabatan'];
	}	
	$golongan_jabatan_id = array(
		'name'=>'golongan_jabatan_id',
		'value'=>( isset($_POST['golongan_jabatan_id'] ) ? $_POST['golongan_jabatan_id'] : $goljab_id  ),
		'id'=>'golongan_jabatan_id' 
		//'onchange'=>'javascript:checkNipar();'		
	);
	$form_temp = form_dropdown($golongan_jabatan_id , $goljabs );
	$view .= form_field_display( $form_temp , "Golongan Jabatan"    );

	$grd_id = isset( $fields['grade_id'] ) ? $fields['grade_id']:  0;
	$grade_id = array(
		'name'=>'grade_id',
		'value'=>( isset($_POST['grade_id'] ) ? $_POST['grade_id'] : $grd_id  ),
		'id'=>'grade_id'  
	);
 
	if($fields){
		$query_grade = "SELECT grade_id FROM gol_grade 
			WHERE golongan_jabatan_id=".$goljab_id." 
			GROUP BY grade_id
			ORDER BY grade_id ASC";
		$result_grade = my_query($query_grade);
		$opsi_pilihan ='';
		while($row_grade = my_fetch_array($result_grade)){
			if($row_grade['grade_id'] == $grd_id){
				$opsi_pilihan .='<option selected value="'.$row_grade['grade_id'].'">'.$row_grade['grade_id'].'</option>';
			}else{
				$opsi_pilihan .='<option value="'.$row_grade['grade_id'].'">'.$row_grade['grade_id'].'</option>';			
			}
			//var_dump($opsi_pilihan);
			$dropdown_extends = dropdown_multi_rows_extends_dua( $golongan_jabatan_id , $grade_id , "combobox_grade.php", $opsi_pilihan);
		}
	}else{	
		$dropdown_extends = dropdown_multi_rows_extends_dua( $golongan_jabatan_id , $grade_id , "combobox_grade.php", false );
	}
	$view .= form_field_display( $dropdown_extends  , "Grade"  );   

	$sumber_pendukungs = array(
		'Sumber' => 'Operasional',
		'Pendukung' => 'Strategis'
	);
	$sumber_pendukung = array(
		'name'=>'sumber_pendukung',
		'value'=>( isset($_POST['sumber_pendukung']) ? $_POST['sumber_pendukung'] : $fields['sumber_pendukung'] ),
		'id'=>'sumber_pendukung', 
		'onchange'=>'javascript:checkNipar();'
	);
	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}

function form_devisi_validate(){
	$errsubmit = false;
	$err = array();
	 
	$code =  trim($_POST["nama_jabatan"]); 
	if( $code == ''){
		$errsubmit = true;
		$err[] = "Nama Jabatan belum di isi";
	}
	if((int) $_POST['departemen_id'] == 0){
		$errsubmit = true;
		$err[] = "Departemen belum di isi";
	}
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}

function form_jabatan_submit($sk_id, $parent_id , $id) {
	 	
	if($id>0){
		$datas = array(
			'nama_jabatan'=>my_type_data_str( $_POST['nama_jabatan'] ),
			'nomor_posisi'=>my_type_data_str( $_POST['nomor_posisi'] ),
			'golongan_jabatan_id'=>my_type_data_int( $_POST['golongan_jabatan_id']  ), 
			'unit_id'=>my_type_data_int( $_POST['unit_id']  ),  
			'grade_id'=>my_type_data_int( $_POST['grade_id']  ),  
			'pos_biaya_id'=>my_type_data_int( $_POST['pos_biaya_id']  ), 
			'datetime_update'=>my_type_data_function('NOW()'), 
			'departemen_id'=>my_type_data_int( $_POST['departemen_id']  ), 
		);	 
		my_update_record('jabatan' ,'jabatan_id' , $id , $datas);
	}else{
		$level=$_POST['level'];
		$parents = my_get_data_by_id('jabatan','jabatan_id',$parent_id);
		 
 		$datas = array( 
			'parent_id'=>my_type_data_int( $parent_id  ), 
			'level'=>my_type_data_int( $level  ), 
			'nama_jabatan'=>my_type_data_str( $_POST['nama_jabatan'] ),
			'nomor_posisi'=>my_type_data_str( $_POST['nomor_posisi'] ), 
			'datetime_added'=>my_type_data_function('NOW()'),
		//	'sumber_pendukung'=>my_type_data_str( $_POST['sumber_pendukung']   ),
			'grade_id'=>my_type_data_int( $_POST['grade_id']  ), 
			'nama_jabatan'=>my_type_data_str( $_POST['nama_jabatan'] ),
			'unit_id'=>my_type_data_int( $_POST['unit_id']  ),  
			'sk_id'=>my_type_data_int( $sk_id ), 
			'pos_biaya_id'=>my_type_data_int( $_POST['pos_biaya_id']  ), 
			'golongan_jabatan_id'=>my_type_data_int( $_POST['golongan_jabatan_id']  ),  
			'departemen_id'=>my_type_data_int( $_POST['departemen_id']  ), 			
		);	
		my_insert_record('jabatan' , $datas);
	}	
	return update_urut() ;
}

function remove_jabatan($id){
	$query= "DELETE FROM jabatan WHERE jabatan_id = {$id}";
	return my_query($query);
} 


/*

		AUTO NUMBER
		
*/

function update_urut(){
return true;/*
   $result = my_query( "SELECT jabatan_id FROM jabatan a 
	   INNER JOIN sk_jabatan b ON b.sk_id=a.sk_id 
	   WHERE b.active='Y'  
	   AND a.parent_id ='0'" );
   // display each child
   $urut =0;
   while ($row = my_fetch_array($result)) {
		$urut++;
		my_query("UPDATE jabatan SET urut =".$urut." 
			WHERE jabatan_id = ".$row['jabatan_id'] );		
		$result2 = my_query( "SELECT jabatan_id FROM jabatan 
			WHERE  parent_id='{$row['jabatan_id']}' 
			ORDER BY  level,nomor_posisi" );
		if(my_num_rows($result2) > 0){
			while($row2 = my_fetch_array($result2)){
				$urut++;
				my_query("UPDATE jabatan SET urut =".$urut." 
					WHERE jabatan_id = ".$row2['jabatan_id'] );		
				$res3 =  my_query( "SELECT jabatan_id FROM jabatan 
					WHERE parent_id='{$row2['jabatan_id']}' 
					ORDER BY level,nomor_posisi" );
				if(my_num_rows($res3) > 0){
					while($row3 = my_fetch_array($res3)){
						$urut++;
						my_query("UPDATE jabatan SET urut =".$urut." 
							WHERE jabatan_id = ".$row3['jabatan_id'] );		
						$result4 = my_query( "SELECT jabatan_id FROM jabatan 
							WHERE parent_id='{$row3['jabatan_id']}' 
							ORDER BY horisontal,level,nomor_posisi" );
						if(my_num_rows($result4) > 0){
							while($row4 = my_fetch_array($result4)){
								$urut++;
								my_query("UPDATE jabatan SET urut =".$urut." 
									WHERE jabatan_id = ".$row4['jabatan_id'] );		
								$result5 = my_query( "SELECT jabatan_id FROM jabatan 
									WHERE parent_id='{$row4['jabatan_id']}' 
									ORDER BY horisontal,level,nomor_posisi" );
								if(my_num_rows($result5) > 0){
									while($row5 = my_fetch_array($result5)){
										$urut++;
										my_query("UPDATE jabatan SET urut =".$urut." 
											WHERE jabatan_id = ".$row5['jabatan_id'] );		
										$result6= my_query( "SELECT jabatan_id FROM jabatan 
											WHERE parent_id='{$row5['jabatan_id']}' 
											ORDER BY horisontal,level,nomor_posisi" );
										if(my_num_rows($result6) > 0){
											while($row6 = my_fetch_array($result6)){
												$urut++;
												my_query("UPDATE jabatan SET urut =".$urut." 
													WHERE jabatan_id = ".$row6['jabatan_id'] );		
												$result7= my_query( "SELECT jabatan_id FROM jabatan 
													WHERE parent_id='{$row6['jabatan_id']}' 
													ORDER BY horisontal,level,nomor_posisi" );
												if(my_num_rows($result7) > 0){
													while($row7 = my_fetch_array($result7)){
														$urut++;
														my_query("UPDATE jabatan SET urut =".$urut." 
															WHERE jabatan_id = ".$row7['jabatan_id'] );		
														$result8= my_query( "SELECT jabatan_id FROM jabatan 
															WHERE parent_id='{$row7['jabatan_id']}' 
															ORDER BY horisontal,level,nomor_posisi" );
														if(my_num_rows($result8) > 0){
															while($row8 = my_fetch_array($result8)){
																$urut++;
																my_query("UPDATE jabatan SET urut =".$urut." 
																	WHERE jabatan_id = ".$row8['jabatan_id'] );		
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
   } */
   return true;
} 		
